package com.crm.controller;

import com.crm.dto.BusinessDTO;
import com.crm.dto.GainDto;
import com.crm.pojo.Business;
import com.crm.pojo.BusinessRecord;
import com.crm.pojo.DictDetail;
import com.crm.pojo.Referredsubject;
import com.crm.result.PageResult;
import com.crm.result.Result;
import com.crm.service.BusinessService;
import com.crm.vo.BusinessVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import net.sf.cglib.core.Local;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.io.DataInput;
import java.time.LocalDateTime;
import java.util.List;

@Slf4j
@RequestMapping
@RestController()
@Api(tags = "商机管理相关接口")
public class BusinessController {
    @Autowired
    private BusinessService businessService;


    @GetMapping("/business/list")
    @ApiOperation("根据条件查询商机")
        public Result<PageResult> queryBusniness(

            @RequestParam(name = "pageNum", defaultValue = "1") int pageNum,
            @RequestParam(name = "pageSize", defaultValue = "10") int pageSize,
            @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
            @RequestParam(name = "params[beginCreateTime]", required = false) LocalDateTime beginCreateTime,
            @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
            @RequestParam(name = "params[endCreateTime]", required = false) LocalDateTime endCreateTime,
            Long id,String name, String phone,String owner, Integer status

    ){
        BusinessDTO dto = BusinessDTO.builder()
                .PageSize(pageSize)
                .pageNum(pageNum).beginCreateTime(beginCreateTime).endCreateTime(endCreateTime).id(id).name(name)
                        .phone(phone).owner(owner).status(status).
                build();

        PageResult businessVO =businessService.queryBusiness(dto);


                return Result.commonSuccess(businessVO);
    }

    /**
     * 新增商机
     */
    @ApiOperation("新增商机")
    @PostMapping("/business")
    public Result addBusiness(@RequestBody Business business){
            businessService.addBusiness(business);
        return Result.success();
    }


    /**
     * 查看商机表详细数据
     */
    @ApiOperation("查看商机表详细数据")
    @GetMapping("/business/{id}")
    public Result getBusinessById(@PathVariable Long id){
        Business business = businessService.getBusinessById(id);
        return Result.success(business);
    }
    /**
     * 查看历史沟通记录
     */

    @ApiOperation("查看历史沟通记录")
    @GetMapping("/business/record/list")
    public Result getHistory(Long businessId){
        List<BusinessRecord> businessVO = businessService.getHistory(businessId);
        return Result.success(businessVO);
    }
/**
 * 查看pool；
 */
@ApiOperation("查看pool")
    @GetMapping("/business/pool")
public Result<PageResult> queryBusninesspool(

        @RequestParam(name = "pageNum", defaultValue = "1") int pageNum,
        @RequestParam(name = "pageSize", defaultValue = "10") int pageSize,
        @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
        @RequestParam(name = "params[beginCreateTime]", required = false) LocalDateTime beginCreateTime,
        @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
        @RequestParam(name = "params[endCreateTime]", required = false) LocalDateTime endCreateTime,
        Long id,String name, String phone,String owner, Integer status

){
    BusinessDTO dto = BusinessDTO.builder()
            .PageSize(pageSize)
            .pageNum(pageNum).beginCreateTime(beginCreateTime).endCreateTime(endCreateTime).id(id).name(name)
            .phone(phone).owner(owner).status(status).
            build();

    PageResult businessVO =businessService.queryBusinesspoll(dto);


    return Result.commonSuccess(businessVO);
}
/**
 * 捞取
 */
@ApiOperation("捞取")
    @PutMapping("/business/gain")
    public Result gain(@RequestBody GainDto gainDto){
        businessService.gain(gainDto);
        return Result.success();
    }





}

